package de.tu_darmstadt.gdi1.battleship.view;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.io.File;
import java.util.Locale;
import java.util.Vector;

import javax.swing.Box;
import javax.swing.ButtonGroup;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JSeparator;
import javax.swing.KeyStroke;
import javax.swing.border.EmptyBorder;

import acm.io.IODialog;
import de.tu_darmstadt.gdi1.battleship.controller.StudentWindowListener;
import de.tu_darmstadt.gdi1.battleship.controller.UserInteraction;
import de.tu_darmstadt.gdi1.battleship.exceptions.InternalFailureException;
import de.tu_darmstadt.gdi1.battleship.exceptions.ParameterOutOfRangeException;
import de.tu_darmstadt.gdi1.battleship.model.BattleshipGame;

public class StudentWindow extends JFrame {


	/**
	 * 
	 */
	private static final long serialVersionUID = -671985989028963327L;

	/**
	 * Launch the Window. For testing purposes only
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			@Override
			public void run() {
				try {
					StudentWindow frame = new StudentWindow("BSG **testing**",
							null);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	// Model
	private BattleshipGame bsg;
	// Controller
	private UserInteraction mainCtrl;
	private StudentWindowListener mainListener;

	// Message History
	private Vector<String> userMsg = new Vector<String>(3);

	// Menu items
	private JPanel contentPane;
	private JMenuBar menuBar;
	private JMenu mnGame;
	private JMenu mnNewGame;
	private JMenuItem mntmRanLoadLvl;
	private JMenuItem mntmRanNewLvl;
	private JMenuItem mntmSelfMade;
	private StudentPanel gamePanel; // Thats were our StudentPanel goes
	private StatusPanel statusPanel;
	private JSeparator separator;
	private JMenuItem mntmSaveGame;
	private JMenuItem mntmLoadGame;
	private JSeparator separator_1;
	private JMenuItem mntmLoadLevel;
	private JMenuItem mntmAbout;
	private JMenuItem mntmSaveLevel;
	private JSeparator separator_2;
	private JMenuItem mntmExit;
	private JMenu mnView;
	private JMenu mnLanguage;
	private ButtonGroup langGroup = new ButtonGroup();
	private JRadioButtonMenuItem rdbtnmntmLangEn;
	private JRadioButtonMenuItem rdbtnmntmLangDe;
	private JMenu mnSkin;
	private JMenuItem mntmLoadSkin;
	private ButtonGroup skinGroup = new ButtonGroup();
	private JRadioButtonMenuItem rdbtnmntmSkinTerminal;
	private JRadioButtonMenuItem rdbtnmntmSkinFische;
	private JRadioButtonMenuItem rdbtnmntmSkinDefault;
	private JRadioButtonMenuItem rdbtnmntmSkinUgly;

	private Box verticalBox;
	private JLabel lblMessages;
	private JLabel lblMessage1;
	private JSeparator separator_3;
	private JSeparator separator_4;
	private JLabel lblMessage2;
	private JSeparator separator_5;
	private JLabel lblMessage3;

	/**
	 * Create the frame.
	 * 
	 * @throws InternalFailureException
	 */
	public StudentWindow(String title, BattleshipGame battleshipGame) {

		super(title);

		this.bsg = battleshipGame;

		// Messages erstellen
		userMsg.add(Messages.getString("StudentWindow.lblSomeMessage.text"));
		userMsg.add(" ");
		userMsg.add(" ");

		// Frame vorbereiten.
		setTitle(title);
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		// Auf Hauptmonitor platzieren.
		Rectangle bounds = GraphicsEnvironment.getLocalGraphicsEnvironment()
				.getDefaultScreenDevice().getDefaultConfiguration().getBounds();
		setBounds(bounds.x + 100, bounds.y + 100, 421, 303);
		setJMenuBar(getMenuBar_1());
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		contentPane.add(getMessagesBox(), BorderLayout.SOUTH);

		// GamePanel laden
		contentPane.add(getGamePanel(), BorderLayout.CENTER);
		getGamePanel().setGamePanelContents();
		
		// Status Panel
		contentPane.add(getStatusPanel(), BorderLayout.EAST);
		getStatusPanel().setActionListener(getMainListener());

		// Controller erstellen
		setMenuActionListener(getMainListener());
		addKeyListener(getMainListener());
	}

	
	
	/**
	 * Dialog which asks for name (OUTDATED)
	 */
	public void askForUsersName() {
		IODialog dialog = new IODialog();
		bsg.setPlayerName(dialog.readLine("Please enter your name"));
	}

	public UserInteraction getCtrl(){
		return mainCtrl;
	}
	
	public BattleshipGame getBsg() {
		return bsg;
	}

	/**
	 * Opens a Dialog that lets the user choose a File. Return null if user
	 * canceled.
	 * 
	 * @param startPoint
	 *            Sets the Location where the Dialog starts. null means Users
	 *            default directory.
	 * 
	 * @return the chosen file or null if canceled.
	 */
	public File getFile(File startPoint) {
		// Erstelle Auswahlobjekt, setze Auswahlmöglichkeit auf File only
		JFileChooser fileChooser = new JFileChooser();
		fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
		fileChooser.setCurrentDirectory(startPoint);
		// Zeige den Dialog an
		int returnVal = fileChooser.showOpenDialog(this);
		// Falls Auswahl erfolgt, gib File zurück, ansonsten null
		if (returnVal == JFileChooser.APPROVE_OPTION) {
			return fileChooser.getSelectedFile();
		}
		return null;
	}

	/**
	 * Opens a Dialog that lets the user choose a Folder. Return null if user
	 * canceled.
	 * 
	 * @param startPoint
	 *            Sets the Location where the Dialog starts. null means Users
	 *            default directory.
	 * 
	 * @return the chosen file or null if canceled.
	 */
	public File getFolder(File startPoint) {
		// Erstelle Auswahlobjekt, setze Auswahlmöglichkeit auf Folder only
		JFileChooser fileChooser = new JFileChooser();
		fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		fileChooser.setCurrentDirectory(startPoint);
		// Zeige den Dialog an
		int returnVal = fileChooser.showOpenDialog(this);
		// Falls Auswahl erfolgt, gib File zurück, ansonsten null
		if (returnVal == JFileChooser.APPROVE_OPTION) {
			return fileChooser.getSelectedFile();
		}
		return null;
	}

	public StudentPanel getGamePanel() {
		if (gamePanel == null) {
			gamePanel = new StudentPanel(this);
			gamePanel.setGamePanelContents();
		}
		return gamePanel;
	}

	public UserInteraction getMainCtrl() {
		if (mainCtrl == null) {
			mainCtrl = new UserInteraction(bsg, this);
		}
		return mainCtrl;
	}


	public JMenuBar getMenuBar_1() {
		if (menuBar == null) {
			menuBar = new JMenuBar();
			menuBar.add(getMnGame());
			menuBar.add(getMnNetwork());
			menuBar.add(getMnView());
			menuBar.add(getMnHelp());
			menuBar.add(getHorizontalGlue());
		}
		return menuBar;

	}

	public JMenuItem getMntmAbout() {
		if (mntmAbout == null) {
			mntmAbout = new JMenuItem(
					Messages.getString("StudentWindow.mntmAbout.text"));
			mntmAbout.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A,
					InputEvent.CTRL_MASK));
		}
		return mntmAbout;

	}

	public JMenu getMnGame() {
		if (mnGame == null) {
			mnGame = new JMenu(Messages.getString("StudentWindow.mnGame.text"));
			mnGame.add(getMnNewGame());
			mnGame.add(getSeparator());
			mnGame.add(getMntmSaveGame());
			mnGame.add(getMntmLoadGame());
			mnGame.add(getSeparator_1());
			mnGame.add(getMntmSaveLevel());
			mnGame.add(getMntmLoadLevel());
			mnGame.add(getSeparator_2_1());
			mnGame.add(getMntmExit());
		}
		return mnGame;
	}

	public JMenu getMnNewGame() {
		if (mnNewGame == null) {
			mnNewGame = new JMenu(
					Messages.getString("StudentWindow.mnNewGame.text"));
			mnNewGame.add(getMntmRanLoadLvl());
			mnNewGame.add(getMntmRanNewLvl());
			mnNewGame.add(getMntmSelfMade());
		}
		return mnNewGame;
	}

	public JMenu getMnLanguage() {
		if (mnLanguage == null) {
			mnLanguage = new JMenu(
					Messages.getString("StudentWindow.mnNewMenu.text_1"));
		}
		mnLanguage.add(getRdbtnmntmLangEn());
		mnLanguage.add(getRdbtnmntmLangDe());

		langGroup.add(getRdbtnmntmLangEn());
		langGroup.add(getRdbtnmntmLangDe());

		return mnLanguage;
	}

	public JRadioButtonMenuItem getRdbtnmntmLangEn() {
		if (rdbtnmntmLangEn == null) {
			rdbtnmntmLangEn = new JRadioButtonMenuItem(
					Messages.getString("StudentWindow.rdbtnmntmNewRadioItem.text_L1"));

		}
		return rdbtnmntmLangEn;
	}

	public JRadioButtonMenuItem getRdbtnmntmLangDe() {
		if (rdbtnmntmLangDe == null) {
			rdbtnmntmLangDe = new JRadioButtonMenuItem(
					Messages.getString("StudentWindow.rdbtnmntmNewRadioItem.text_L2"));
		}
		return rdbtnmntmLangDe;
	}

	public JMenu getMnSkin() {
		if (mnSkin == null) {
			mnSkin = new JMenu(
					Messages.getString("StudentWindow.mnNewMenu.text_2"));
			mnSkin.add(getRdbtnmntmSkinDefault());
			mnSkin.add(getRdbtnmntmSkinTerminal());
			mnSkin.add(getRdbtnmntmSkinUgly());
			mnSkin.add(getRdbtnmntmSkinFische());
			mnSkin.add(getMntmLoadSkin());

			skinGroup.add(getRdbtnmntmSkinDefault());
			skinGroup.add(getRdbtnmntmSkinTerminal());
			skinGroup.add(getRdbtnmntmSkinUgly());
			skinGroup.add(getRdbtnmntmSkinFische());
		}
		return mnSkin;
	}

	public JMenuItem getMntmRanLoadLvl() {
		if (mntmRanLoadLvl == null) {
			mntmRanLoadLvl = new JMenuItem(
					Messages.getString("StudentWindow.mntmRanLoadLvl.text"));
		}
		return mntmRanLoadLvl;
	}

	public JMenuItem getMntmRanNewLvl() {
		if (mntmRanNewLvl == null) {
			mntmRanNewLvl = new JMenuItem(
					Messages.getString("StudentWindow.mntmRanNewLvl.text"));
		}
		return mntmRanNewLvl;
	}

	public JMenuItem getMntmSelfMade() {
		if (mntmSelfMade == null) {
			mntmSelfMade = new JMenuItem(
					Messages.getString("StudentWindow.mntmSelfMade.text"));
		}
		return mntmSelfMade;
	}
	
	
	public JMenuItem getMntmExit() {
		if (mntmExit == null) {
			mntmExit = new JMenuItem(Messages.getString("StudentWindow.mntmNewMenuItem.text_4")); //$NON-NLS-1$
			mntmExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.ALT_MASK));
			}
		return mntmExit;
	}

	public JMenuItem getMntmLoadGame() {
		if (mntmLoadGame == null) {
			mntmLoadGame = new JMenuItem(
					Messages.getString("StudentWindow.mntmNewMenuItem.text_1")); //$NON-NLS-1$
			mntmLoadGame.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,
					InputEvent.CTRL_MASK));
		}
		return mntmLoadGame;
	}

	public JMenuItem getMntmLoadLevel() {
		if (mntmLoadLevel == null) {
			mntmLoadLevel = new JMenuItem(
					Messages.getString("StudentWindow.mntmNewMenuItem.text_2")); //$NON-NLS-1$
			mntmLoadLevel.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,
					InputEvent.ALT_MASK));
		}
		return mntmLoadLevel;
	}

	public JMenuItem getMntmLoadSkin() {
		if (mntmLoadSkin == null) {
			mntmLoadSkin = new JMenuItem(
					Messages.getString("StudentWindow.mntmLoadSkin.text")); //$NON-NLS-1$
		}
		return mntmLoadSkin;
	}

	// KeyListener implementation:

	public JMenuItem getMntmSaveGame() {
		if (mntmSaveGame == null) {
			mntmSaveGame = new JMenuItem(
					Messages.getString("StudentWindow.mntmNewMenuItem.text")); //$NON-NLS-1$
			mntmSaveGame.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
					InputEvent.CTRL_MASK));
		}
		return mntmSaveGame;
	}

	public JMenuItem getMntmSaveLevel() {
		if (mntmSaveLevel == null) {
			mntmSaveLevel = new JMenuItem(
					Messages.getString("StudentWindow.mntmNewMenuItem.text_3")); //$NON-NLS-1$
			mntmSaveLevel.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
					InputEvent.ALT_MASK));
		}
		return mntmSaveLevel;
	}

	public JMenu getMnView() {
		if (mnView == null) {
			mnView = new JMenu(
					Messages.getString("StudentWindow.mnNewMenu.text"));
			mnView.add(getMnLanguage());
			mnView.add(getMnSkin());
		}
		return mnView;
	}

	public JRadioButtonMenuItem getRdbtnmntmSkinDefault() {
		if (rdbtnmntmSkinDefault == null) {
			rdbtnmntmSkinDefault = new JRadioButtonMenuItem(
					Messages.getString("StudentWindow.rdbtnmntmNewRadioItem.text")); //$NON-NLS-1$
		}
		return rdbtnmntmSkinDefault;
	}

	public JRadioButtonMenuItem getRdbtnmntmSkinUgly() {
		if (rdbtnmntmSkinUgly == null) {
			rdbtnmntmSkinUgly = new JRadioButtonMenuItem(
					Messages.getString("StudentWindow.rdbtnmntmNewRadioItem.text_1")); //$NON-NLS-1$
		}
		return rdbtnmntmSkinUgly;
	}

	public JRadioButtonMenuItem getRdbtnmntmSkinTerminal() {
		if (rdbtnmntmSkinTerminal == null) {
			rdbtnmntmSkinTerminal = new JRadioButtonMenuItem(
					Messages.getString("StudentWindow.rdbtnmntmNewRadioItem.text_2")); //$NON-NLS-1$
		}
		return rdbtnmntmSkinTerminal;
	}

	public JRadioButtonMenuItem getRdbtnmntmSkinFische() {
		if (rdbtnmntmSkinFische == null) {
			rdbtnmntmSkinFische = new JRadioButtonMenuItem(
					Messages.getString("StudentWindow.rdbtnmntmNewRadioItem.text_3")); //$NON-NLS-1$
		}
		return rdbtnmntmSkinFische;
	}

	public JSeparator getSeparator() {
		if (separator == null) {
			separator = new JSeparator();
		}
		return separator;
	}

	public JSeparator getSeparator_1() {
		if (separator_1 == null) {
			separator_1 = new JSeparator();
		}
		return separator_1;
	}

	public JSeparator getSeparator_2_1() {
		if (separator_2 == null) {
			separator_2 = new JSeparator();
		}
		return separator_2;
	}

	/**
	 * fits the size of the Panel and Window when a new Level or Skin was
	 * loaded.
	 * 
	 * @param width
	 *            levelwidth
	 * @param height
	 *            levelheight
	 * @throws InternalFailureException
	 * @throws ParameterOutOfRangeException
	 */
	public void notifyLevelLoaded(int width, int height)
			throws ParameterOutOfRangeException, InternalFailureException {

		getGamePanel().notifyLevelLoaded(width, height);

	}

	public void setMainCtrl(UserInteraction mainCtrl) {
		this.mainCtrl = mainCtrl;
	}

	/**
	 * Sets the ActionListener for all entries in Menu.
	 * 
	 * @param al
	 */
	public void setMenuActionListener(ActionListener al) {
		getMntmRanLoadLvl().addActionListener(al);
		getMntmRanNewLvl().addActionListener(al);
		getMntmSelfMade().addActionListener(al);
		getMntmLoadSkin().addActionListener(al);
		getMntmLoadLevel().addActionListener(al);
		getMntmSaveGame().addActionListener(al);
		getMntmLoadGame().addActionListener(al);
		getMntmSaveLevel().addActionListener(al);
		getMntmAbout().addActionListener(al);

		getRdbtnmntmLangEn().addActionListener(al);
		getRdbtnmntmLangDe().addActionListener(al);

		getRdbtnmntmSkinDefault().addActionListener(al);
		getRdbtnmntmSkinUgly().addActionListener(al);
		getRdbtnmntmSkinTerminal().addActionListener(al);
		getRdbtnmntmSkinFische().addActionListener(al);
		
		getMnHostGame().addActionListener(al);
		getMnJoinGame().addActionListener(al);
		getMntmRestoreLocalGame().addActionListener(al);

		getMntmExit().addActionListener(al);

	}

	public void showMessage(String msg) {
		userMsg.add(0, msg);
		updateMessages();
	}

	public void updateMessages() {
		getLblMessage1().setText(userMsg.get(0));
		getLblMessage2().setText(userMsg.get(1));
		getLblMessage3().setText(userMsg.get(2));
	}

	public Box getMessagesBox() {
		if (verticalBox == null) {
			verticalBox = Box.createVerticalBox();

			verticalBox.add(getLblMessages());
			verticalBox.add(getSeparator_3());
			verticalBox.add(getLblMessage1());
			verticalBox.add(getSeparator_4());
			verticalBox.add(getLblMessage2());
			verticalBox.add(getSeparator_5());
			verticalBox.add(getLblMessage3());
		}
		return verticalBox;
	}

	public JLabel getLblMessages() {
		if (lblMessages == null) {
			lblMessages = new JLabel(
					Messages.getString("StudentWindow.lblMessages.text_1")); //$NON-NLS-1$
		}
		return lblMessages;
	}

	public JLabel getLblMessage1() {
		if (lblMessage1 == null) {
			lblMessage1 = new JLabel(userMsg.get(0));
			lblMessage1.setFont(new Font("Dialog", Font.PLAIN, 11));
		}
		return lblMessage1;
	}

	public JSeparator getSeparator_3() {
		if (separator_3 == null) {
			separator_3 = new JSeparator();
		}
		return separator_3;
	}

	public JSeparator getSeparator_4() {
		if (separator_4 == null) {
			separator_4 = new JSeparator();
		}
		return separator_4;
	}

	public JLabel getLblMessage2() {
		if (lblMessage2 == null) {
			lblMessage2 = new JLabel(userMsg.get(1)); //$NON-NLS-1$
			lblMessage2.setFont(new Font("Dialog", Font.PLAIN, 11));
		}
		return lblMessage2;
	}

	public JSeparator getSeparator_5() {
		if (separator_5 == null) {
			separator_5 = new JSeparator();
		}
		return separator_5;
	}

	public JLabel getLblMessage3() {
		if (lblMessage3 == null) {
			lblMessage3 = new JLabel(userMsg.get(2)); //$NON-NLS-1$
			lblMessage3.setFont(new Font("Dialog", Font.PLAIN, 11));
		}
		return lblMessage3;
	}

	/**
	 * @return the mainListener
	 */
	public StudentWindowListener getMainListener() {
		if (mainListener == null) {
			mainListener = new StudentWindowListener(getBsg(), this,
					getMainCtrl());
		}
		return mainListener;
	}

	public void setLocale(Locale l) {
		Messages.setLocale(l);
	}

	public void resetJMenu() {
		mnGame.setText(Messages.getString("StudentWindow.mnGame.text"));
		mnNewGame.setText(Messages.getString("StudentWindow.mnNewGame.text"));
		mntmRanLoadLvl.setText(Messages
				.getString("StudentWindow.mntmRanLoadLvl.text"));
		mntmRanNewLvl.setText(Messages
				.getString("StudentWindow.mntmRanNewLvl.text"));
		mntmSelfMade.setText(Messages
				.getString("StudentWindow.mntmSelfMade.text"));
		mntmSaveGame.setText(Messages
				.getString("StudentWindow.mntmNewMenuItem.text"));
		mntmLoadGame.setText(Messages
				.getString("StudentWindow.mntmNewMenuItem.text_1"));
		mntmLoadLevel.setText(Messages
				.getString("StudentWindow.mntmNewMenuItem.text_2"));
		mntmSaveLevel.setText(Messages
				.getString("StudentWindow.mntmNewMenuItem.text_3"));
		mntmExit.setText(Messages
				.getString("StudentWindow.mntmNewMenuItem.text_4"));
		mnView.setText(Messages.getString("StudentWindow.mnNewMenu.text"));
		mnLanguage
				.setText(Messages.getString("StudentWindow.mnNewMenu.text_1"));
		rdbtnmntmLangEn.setText(Messages
				.getString("StudentWindow.rdbtnmntmNewRadioItem.text_L1"));
		rdbtnmntmLangDe.setText(Messages
				.getString("StudentWindow.rdbtnmntmNewRadioItem.text_L2"));
		mnSkin.setText(Messages.getString("StudentWindow.mnNewMenu.text_2"));
		mntmLoadSkin.setText(Messages
				.getString("StudentWindow.mntmLoadSkin.text"));
		rdbtnmntmSkinDefault.setText(Messages
				.getString("StudentWindow.rdbtnmntmNewRadioItem.text"));
		rdbtnmntmSkinUgly.setText(Messages
				.getString("StudentWindow.rdbtnmntmNewRadioItem.text_1"));
		rdbtnmntmSkinTerminal.setText(Messages
				.getString("StudentWindow.rdbtnmntmNewRadioItem.text_2"));
		rdbtnmntmSkinFische.setText(Messages
				.getString("StudentWindow.rdbtnmntmNewRadioItem.text_3"));
		mntmAbout.setText(Messages.getString("StudentWindow.mntmAbout.text"));
		options[1]=(Messages.getString("StudentWindow.geheimbutton.text"));
		title=(Messages.getString("StudentWindow.aboutTitle.text"));
		content=(Messages.getString("StudentWindow.aboutContent.text"));
		
		getStatusPanel().getLblName().setText(Messages.getString("StatusPanel.lblName.text"));
		getStatusPanel().getTxtPlayer().setText(Messages.getString("StatusPanel.txtPlayer.text"));
		getStatusPanel().getLblTurn().setText(Messages.getString("StatusPanel.lblTurn.text"));
		getStatusPanel().getLblYou().setText(Messages.getString("StatusPanel.lblYou.text"));
		getStatusPanel().getLblTime().setText(Messages.getString("StatusPanel.lblTime.text"));
		getStatusPanel().getLabel().setText(Messages.getString("StatusPanel.label.text"));
		getStatusPanel().getLblGameMode().setText(Messages.getString("StatusPanel.lblGameMode.text"));
		getStatusPanel().getChckbxShootsPerPart().setText(Messages.getString("StatusPanel.chckbxShootsPerPart.text"));
		getStatusPanel().getLblHowManyShots().setText(Messages.getString("StatusPanel.lblHowManyShots.text"));
		
		mnNetwork.setText(Messages.getString("StudentWindow.mnNetwork.text")); //$NON-NLS-1$
		mnHostGame.setText(Messages.getString("StudentWindow.mnHostGame.text")); //$NON-NLS-1$
		mnJoinGame.setText(Messages.getString("StudentWindow.mnJoinGame.text")); //$NON-NLS-1$
		mntmRestoreLocalGame.setText(Messages.getString("StudentWindow.mntmRestoreLocalGame.text")); //$NON-NLS-1$
		
		getStatusPanel().getLblWinRatio().setText(Messages.getString("StatusPanel.lblWinRatio.text")); //$NON-NLS-1$
		
		
	}

	/**
	 * @param mainListener
	 *            the mainListener to set
	 */
	public void setMainListener(StudentWindowListener mainListener) {
		this.mainListener = mainListener;
	}

	public Object[] options = { "OK",
			Messages.getString("StudentWindow.geheimbutton.text") };
	String content=Messages.getString("StudentWindow.aboutContent.text");
	String title=Messages.getString("StudentWindow.aboutTitle.text");
	private Component horizontalGlue;
	private JMenu mnHelp;
	private JMenu mnNetwork;
	private JMenuItem mnHostGame;
	private JMenuItem mnJoinGame;
	private JMenuItem mntmRestoreLocalGame;
	
	
	public void openAbout() {

		int selected = JOptionPane.showOptionDialog(null,
				content,title,
				JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
				null, options, options[0]);

		if (selected == 1)
			getGamePanel()
			.loadSkin(
					new Skin(
							new File(
									"src/de/tu_darmstadt/gdi1/resources/images/spaceships")));

	try {
		getGamePanel().redraw();
	} catch (InternalFailureException e) {
		return;
	}
	;
		
	}
	public Component getHorizontalGlue() {
		if (horizontalGlue == null) {
			horizontalGlue = Box.createHorizontalGlue();
		}
		return horizontalGlue;
	}
	public JMenu getMnHelp() {
		if (mnHelp == null) {
			mnHelp = new JMenu(Messages.getString("StudentWindow.mnHelp.text")); //$NON-NLS-1$
			mnHelp.add(getMntmAbout());
		}
		return mnHelp;
	}

	/**
	 * @return the statusPanel
	 */
	public StatusPanel getStatusPanel() {
		if(statusPanel == null) {
			statusPanel = new StatusPanel(bsg);
		}
		return statusPanel;
	}
	
	
	public JMenu getMnNetwork() {
		if (mnNetwork == null) {
			mnNetwork = new JMenu(Messages.getString("StudentWindow.mnNetwork.text")); //$NON-NLS-1$
			mnNetwork.add(getMnHostGame());
			mnNetwork.add(getMnJoinGame());
			mnNetwork.add(getMntmRestoreLocalGame());
		}
		return mnNetwork;
	}
	public JMenuItem getMnHostGame() {
		if (mnHostGame == null) {
			mnHostGame = new JMenuItem(Messages.getString("StudentWindow.mnHostGame.text")); //$NON-NLS-1$
		}
		return mnHostGame;
	}
	public JMenuItem getMnJoinGame() {
		if (mnJoinGame == null) {
			mnJoinGame = new JMenuItem(Messages.getString("StudentWindow.mnJoinGame.text")); //$NON-NLS-1$
		}
		return mnJoinGame;
	}
	public JMenuItem getMntmRestoreLocalGame() {
		if (mntmRestoreLocalGame == null) {
			mntmRestoreLocalGame = new JMenuItem(Messages.getString("StudentWindow.mntmRestoreLocalGame.text")); //$NON-NLS-1$
		}
		return mntmRestoreLocalGame;
	}
}
